package com.atguigu.yygh.user.controller.admin;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.model.user.UserInfo;
import com.atguigu.yygh.user.service.UserInfoService;
import com.atguigu.yygh.vo.user.UserInfoQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @program: yygh_parent
 * @author: Mr.Zhuo
 * @create: 2022-03-16 17:17
 **/
@Api("用户管理系统")
@RestController
@RequestMapping("/admin/user")
public class UserController {

    @Autowired
    private UserInfoService userInfoServicel;

    @ApiOperation("条件分页查询数据")
    @GetMapping("/{page}/{limit}")
    public R getPageList(
            @PathVariable("page") Long page,
            @PathVariable("limit") Long limit,
            UserInfoQueryVo userInfoQueryVo
    ) {
        IPage<UserInfo> userInfoPage = new Page<>(page, limit);
        IPage<UserInfo> pageModel =
                userInfoServicel.selectPage(userInfoPage,userInfoQueryVo);

        return R.ok().data("pageModel", userInfoPage);
    }

    @ApiOperation("更改用户锁定或者正常的操作")
    @GetMapping("lock/{id}/{status}")
    public R lock(@PathVariable("id") Integer id,
                  @PathVariable("status") Integer status) {
        userInfoServicel.updateStatus(id, status);
        return R.ok();
    }

    @ApiOperation("查看用户的具体详细信息")
    @GetMapping("show/{id}")
    public R show(@PathVariable("id") Long id) {
        Map<String, Object> map = userInfoServicel.show(id);
        return R.ok().data(map);
    }

    @ApiOperation("审批用户是否认证成功")
    @GetMapping("approval/{id}/{authStatus}")
    public R approval(@PathVariable("id")Integer id,
                      @PathVariable("authStatus")Integer authStatus){
        userInfoServicel.updateAuthStatus(id, authStatus);
        return R.ok();
    }
}
